//
//  historyRecoverView.m
//  Runone
//
//  Created by runone02 on 16/8/17.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "HistoryRecoverView.h"
#import "Masonry.h"
#import "GuestCarViewController.h"
@interface HistoryRecoverView ()<UITextFieldDelegate>

@end

@implementation HistoryRecoverView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUp];
        [self configUI];
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self configUI];
}

- (void) setUp {
    __weak __typeof(self)weakSelf = self;
    self.backgroundColor = [UIColor whiteColor];
    _g = [[GuestCarViewController alloc] init];
    _g.carID=^(NSString *str){
        weakSelf.vehicleNoField.text=str;
    };
}

- (void)configUI {
    __weak __typeof(self)weakSelf = self;
    // 车辆号码label
    self.vehicleNoLabel      = [[UILabel alloc]init];
    if (self.vehicleNoLabel.text==nil) {
        self.vehicleNoLabel.text = @"车牌号码:";
    }
    
    self.vehicleNoLabel.font = [UIFont systemFontOfSize:17];
    [self addSubview:self.vehicleNoLabel];
    [self.vehicleNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
    }];
    //     车辆号码field
    self.vehicleNoField      = [[UITextField alloc]init];
    self.vehicleNoField.placeholder    = @"陕KB5823";
    self.vehicleNoField.text=self.g.Name;
    
    self.vehicleNoField.textColor     = [UIColor lightGrayColor];
    self.vehicleNoField.borderStyle   = UITextBorderStyleBezel;
    self.vehicleNoField.font          = [UIFont systemFontOfSize:17];
    [self.vehicleNoField addTarget:self action:@selector(vehicleNoFieldClick:) forControlEvents:UIControlEventTouchDown];
    self.vehicleNoField.tag           = 3;
    
    [self addSubview:self.vehicleNoField];
    [self.vehicleNoField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.vehicleNoLabel.mas_top);
        make.width.mas_equalTo(200);
        make.right.equalTo(weakSelf.mas_right).with.offset(-10);
    }];
    
    //开始时间label
    self.beginTimeLabel      = [[UILabel alloc]init];
    self.beginTimeLabel.text = @"开始时间:";
    self.beginTimeLabel.font = [UIFont systemFontOfSize:17];
    [self addSubview:self.beginTimeLabel];
    [self.beginTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.vehicleNoLabel.mas_bottom).with.offset(20);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
        
    }];
    // 开始时间field
    self.beginTimeBtn               = [UIButton buttonWithType:UIButtonTypeCustom];
    self.beginTimeBtn .titleLabel.font = [UIFont systemFontOfSize:15];
    self.beginTimeBtn .titleLabel.textAlignment = NSTextAlignmentLeft;
    self.beginTimeBtn .backgroundColor = [UIColor lightGrayColor];
    self.beginTimeBtn.tag           = 4;
    [self.beginTimeBtn addTarget:self action:@selector(timeFieldClick:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:self.beginTimeBtn];
    [self.beginTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.beginTimeLabel.mas_top);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
        make.right.equalTo(weakSelf.mas_right).with.offset(-10);
    }];
    
    //结束时间label
    self.overTimeLabel      = [[UILabel alloc]init];
    self.overTimeLabel.text = @"结束时间:";
    self.overTimeLabel.font = [UIFont systemFontOfSize:17];
    [self addSubview:self.overTimeLabel];
    [self.overTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.beginTimeLabel.mas_bottom).with.offset(20);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
        make.width.mas_equalTo(200);
    }];
    // 结束时间field
    self.overTimeBtn               = [UIButton buttonWithType:UIButtonTypeCustom];
    self.overTimeBtn .titleLabel.font = [UIFont systemFontOfSize:15];
    self.overTimeBtn .titleLabel.textAlignment = NSTextAlignmentLeft;
    self.overTimeBtn .backgroundColor = [UIColor lightGrayColor];
    self.overTimeBtn.tag           = 5;
    [self.overTimeBtn addTarget:self action:@selector(timeFieldClick:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:self.overTimeBtn];
    [self.overTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.overTimeLabel.mas_top);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
        make.right.equalTo(weakSelf.mas_right).with.offset(-10);
    }];
    //取消按钮
    self.cancelBtn     = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    self.cancelBtn.tag = 1;
    self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.cancelBtn setBackgroundColor:[UIColor blueColor]];
    [self.cancelBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:self.cancelBtn];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.overTimeBtn.mas_bottom).with.offset(10);
        make.left.equalTo(weakSelf.mas_left).with.offset(10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(130);
    }];
    //确定
    self.confirmBtn     = [UIButton buttonWithType:UIButtonTypeCustom];
    self.confirmBtn.tag = 2;
    [self.confirmBtn setTitle:@"确认" forState:UIControlStateNormal];
    [self.confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.confirmBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchDown];
    [self.confirmBtn setBackgroundColor:[UIColor blueColor]];
    [self addSubview:self.confirmBtn];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.overTimeBtn.mas_bottom).with.offset(10);
        make.right.equalTo(weakSelf.mas_right).with.offset(-10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(130);
    }];
}

-(void)getCarNumber:(NSString *)carNumber {
    self.vehicleNoField.text=carNumber;
}

#pragma mark - 监听事件
- (void)cancelBtnClick:(UIView *)view {
    NSLog(@"取消按钮");
    if(self.btnClick) {
        self.btnClick(view.tag);
    }
}

- (void)confirmBtnClick:(UIButton *)view {
    NSLog(@"确认按钮");
    if (self.btnClick) {
        self.btnClick(view.tag);
        //       self.ConBlock(self.beginTimeField.text,self.overTimeField.text);
    }
    
}

- (void)vehicleNoFieldClick:(UIView *)view{
    if (self.btnClick) {
        self.btnClick(view.tag);
    }
}

- (void)timeFieldClick:(UIView *)view {
    if (self.btnClick) {
        self.btnClick(view.tag);
    }
}

@end
